from flask import Blueprint
from flask_restx import Api

from app.role_control import (
    AdminBluPrintControl,
    AdminUserManageControl,
    ImageManageControl,
    LogMonitorControl,
    MonitorManageControl,
    SystemManageControl,
    SystemMonitorControl,
    VmMonitorControl, VmImagesUpdateDestroyAPIRuleControl, FlavorsListAPIRuleControl, VmImagesAPIRuleControl,
    SystemMonitoringAPIRuleControl, VirtualMachinesMonitoringAPIRuleControl, LogsMonitoringAPIRuleControl,
    UsersListCreateAPIRuleControl, UsersRetrieveUpdateDestroyAPIRuleControl, UsersBulkOperationsAPIRuleControl,
)

# 系统管理后台
AdminBluPrint = Blueprint(
    "admin", __name__, url_prefix="/v1/admin", role_control=AdminBluPrintControl
)

# 系统管理模块
SystemManage = Blueprint("system_manage", __name__, role_control=SystemManageControl)
AdminBluPrint.register_blueprint(SystemManage)
# 镜像管理
ImageMange = Blueprint("image_manage", __name__, role_control=ImageManageControl)
SystemManage.register_blueprint(ImageMange)
image_manage = Api(ImageMange)

# 监控管理
MonitorManage = Blueprint("monitor_manage", __name__, role_control=MonitorManageControl)
AdminBluPrint.register_blueprint(MonitorManage)
# 系统监控
SystemMonitor = Blueprint("system_monitor", __name__, role_control=SystemMonitorControl)
MonitorManage.register_blueprint(SystemMonitor)
system_monitor = Api(SystemMonitor)
# 虚拟机监控
VmMonitor = Blueprint("vm_monitor", __name__, role_control=VmMonitorControl)
MonitorManage.register_blueprint(VmMonitor)
vm_monitor = Api(VmMonitor)
# 日志管理
LogMonitor = Blueprint("log_monitor", __name__, role_control=LogMonitorControl)
MonitorManage.register_blueprint(LogMonitor)
log_monitor = Api(LogMonitor)

# 用户管理
AdminUserManage = Blueprint(
    "admin_user_manage", __name__, role_control=AdminUserManageControl
)
AdminBluPrint.register_blueprint(AdminUserManage)
admin_user_manage = Api(AdminUserManage)

from . import images, surveillance_system, users  # isort:skip

# 镜像管理
image_manage.add_resource(
    images.VmImagesUpdateDestroyAPI, "/vm/images/<int:vm_image_id>",
    role_control=VmImagesUpdateDestroyAPIRuleControl,
)
# 虚拟机配置
image_manage.add_resource(
    images.FlavorsListAPI, "/vm/flavors",
    role_control=FlavorsListAPIRuleControl,
)
# 镜像列表/上传
image_manage.add_resource(
    images.VmImagesAPI, "/vm/images",
    role_control=VmImagesAPIRuleControl,
)

# 系统监控
system_monitor.add_resource(
    surveillance_system.SystemMonitoringAPI, "/monitors/system_old",
    role_control=SystemMonitoringAPIRuleControl,
)
#监控stack
system_monitor.add_resource(
    surveillance_system.NewSystemMonitoringAPI, "/monitors/system",
    role_control=SystemMonitoringAPIRuleControl,
)


# 虚拟机监控
vm_monitor.add_resource(
    surveillance_system.VirtualMachinesMonitoringAPI, "/monitors/vms",
    role_control=VirtualMachinesMonitoringAPIRuleControl,
)
# 日志监控
log_monitor.add_resource(
    surveillance_system.LogsMonitoringAPI, "/monitors/logs",
    role_control=LogsMonitoringAPIRuleControl,
)


# 用户列表/创建用户
admin_user_manage.add_resource(
    users.UsersListCreateAPI, "/users",
    role_control=UsersListCreateAPIRuleControl,
)
# 用户详情/修改用户/删除用户
admin_user_manage.add_resource(
    users.UsersRetrieveUpdateDestroyAPI, "/users/<int:user_id>",
    role_control=UsersRetrieveUpdateDestroyAPIRuleControl,
)
# 导入模板下载/批量操作
admin_user_manage.add_resource(
    users.UsersBulkOperationsAPI, "/users/bulk/operations",
    role_control=UsersBulkOperationsAPIRuleControl,
)
